<template>
  <view class="goods-item" @click="goToDetail(goods.goods_id)">
    <view class="goods-item-left">
      <radio
        v-if="isShowRadio"
        @click.stop="changeState"
        color="#c00000"
        :checked="goods.goods_state"
      />
      <image
        class="goods-pic"
        :src="goods.goods_small_logo || defaultPic"
        mode="scaleToFill"
      />
    </view>
    <view class="goods-item-right">
      <view class="goods-name">{{ goods.goods_name }} </view>
      <view class="goods-plice-number" @click.stop="">
        <view class="goods-price"
          ><text>￥{{ goods.goods_price | toFix }}</text>
        </view>
        <uni-number-box
          v-if="isShowNumber"
          v-model="goods.goods_count"
          :min="1"
          @change="changeNumber"
        />
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    isShowRadio: {
      typeof: Boolean,
      default: false
    },
    isShowNumber: {
      typeof: Boolean,
      default: false
    },
    goods: {
      type: Object,
      default: () => {}
    }
  },
  data () {
    return {
      // 默认的空图片
      defaultPic:
        'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
    }
  },
  // 价格后面加00
  filters: {
    toFix (val) {
      return Number(val).toFixed(2)
    }
  },
  methods: {
    // 点击变化价格
    changeNumber (val) {
      // console.log(this.goods)
      this.$emit('number-change', {
        goods_id: this.goods.goods_id,
        goods_count: val
      })
    },
    // 点击变化选中状态
    changeState () {
      // console.log(this.goods)
      this.$emit('radio-change', {
        goods_id: this.goods.goods_id,
        goods_state: !this.goods.goods_state
      })
    },
    // 点击跳转详情
    goToDetail (id) {
      uni.navigateTo({ url: '/subpkg/goods-detail/index?goods_id=' + id })
    }
  }
}
</script>

<style lang="scss" scoped>
.goods-item {
  display: flex;
  padding: 10px 5px;
  border-bottom: 1px solid #f0f0f0;

  .goods-item-left {
    display: flex;
    align-items: center;
    margin-right: 5px;

    .goods-pic {
      width: 100px;
      height: 100px;
      display: block;
    }
  }

  .goods-item-right {
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .goods-name {
      font-size: 13px;
    }
    .goods-plice-number {
      display: flex;
      // justify-content: space-around;
      // align-items: center;
      .goods-price {
        margin-right: 10px;
        font-size: 16px;
        color: #c00000;
      }
    }
  }
}
</style>
